package com.pocket.insight.base.exception;

import com.pocket.insight.base.dto.ResponseCodeEnum;
import com.pocket.insight.base.dto.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 描述：统一异常处理器
 *
 * @author zhaozhile
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BizException.class)
    @ResponseBody
    public Result exceptionHandler(BizException e){
        return Result.error(e.getErrCode(), e.getMessage());
    }

    @ExceptionHandler(SysException.class)
    @ResponseBody
    public Result exceptionHandler(SysException e){
        return Result.error(e.getErrCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result exceptionHandler(Exception e){
        log.error("系统异常", e);
        return Result.error(ResponseCodeEnum.ERROR.getCode(), e.getMessage());
    }

}
